<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<title>LPN</title>
	<script type="text/javascript">
		var filterParam = {};
		var datatable_content;
		var lpnNo;
		 $(function() {
			 initTable();
	       });
		function initTable(){
			datatable_content = $("#contentTable").dataTable({
			   "bServerSide":true,
			   "bAutoWidth":false,
	           "sAjaxSource":'${ctx}/v2_lpn/queryLPN',
	           "fnServerData": callback,
	           "fnRowCallback":rowCallBack,
	           //"sScrollX":"120%",
	           "bFilter": false,
	           "bSort": false,
	           "sZeroRecords": "查询无记录！",
	           "bProcessing": true,
	           "oLanguage": {
	               "sUrl": '${ctx}/static/v2/js/plugins/datatables/cn.txt'
	            },
	             "aoColumns":[
	             	 {"mData": null},
	             	 {"mData": null},
	             	 {"mData": "lpnNo"},
	             	 {"mData": "orderNo"},
	             	 {"mData": null},
	             	 {"mData": null},
	             	 {"mData": null},
	             ],
	             "aoColumnDefs":[
	             	{"aTargets": [1],
		              "mRender": function (data, display, row) {
		            	  <c:forEach items="${warehouseList}" var="warehouse">
							if("${warehouse.groupCode}" == row.warehouseCode){
								return "${warehouse.groupName}";
							}
						</c:forEach>
						return "";
			           }
		            },
		            {"aTargets": [4],
			              "mRender": function (data, display, row) {
								return  row.storageType==0 ? "默认收货用" :
									    row.storageType==1 ? "托盘":"箱子";
				           }
			            },
	             	{"aTargets": [5],
		              "mRender": function (data, display, row) {
							return  row.status=="0" ? "空闲" : "使用中";
			           }
		            },
		            {"aTargets": [6],
			              "mRender": function (data, display, row) {
			            	 var rs = "<a href=\"#selextPrinter\"  data-toggle=\"modal\" class=\"btn btn-primary\" onclick=\"initPrinter('"+(row.lpnNo)+"');\" >打印条码</a>";
							rs+="<a href=\"#\"  data-toggle=\"modal\" class=\"btn btn-primary\" onclick=\"deleteLPN('"+(row.id)+"');\" >删除</a>";
			            	 return rs;	

				           }
				     },
		            
	             	
	             ]
			});
		}
		function filter(item){
			filterParam[item.name] = item;
		}
		function callback(sSource, aoData, fnCallback ) {
		   	var formParam = $("#queryForm").serializeArray();
			for(var n in filterParam){
				formParam.push(filterParam[n]);
			}
		   $.ajax({ 
		       "type": "post",
		       "contentType": "application/json", 
		       "url": sSource,    
		       "dataType": "json",   
		       "data": JSON.stringify(aoData.concat(formParam)),
		       "success": fnCallback  
		   });
		}
		/**
		*创建了行的回调
		*nRow为当前的tr
		*/
		function rowCallBack(nRow, aData, iDisplayIndex, iDisplayIndexFull){
			var iDisplayStart = datatable_content.fnSettings()._iDisplayStart;
			$("td:eq(0)", nRow).html(iDisplayStart+iDisplayIndex+1);
		}
		
		function load(){
			if($("#queryForm").valid()){
				if (datatable_content) {
					datatable_content.fnDestroy();
				}
				initTable();
			}
		}
	  function deleteLPN(id){
		  $.ajax({
			   type : 'post',
				url : '${ctx}/v2_lpn/deleteLPN',
				async:false,
				data : {
					id:id
				},
				dataType : 'json',
				success : function(data) {
					var status=data.status;
					var content = data.content;
					if( status=='success'){
				    	window.location.href = "${ctx}/v2_lpn/v2_show";
					}else{
						alert(content);
					}
				},
				error : function() {
					jAlert("网络繁忙，请稍后重试...删除","温馨提示");
				}
			}); 
	  }
	
	  
	  //init打印机
	  function initPrinter(lpn) {
		  lpnNo=lpn;
		  packFormPrinter("printerBody");
	  }
	//打印
	  function clickPrinter() {  
	       //打印
		   var printName = $("#printerBody").val();
			var boxCode=lpnNo;
			printBarCode(printName, boxCode);
			$("#curCode").html(boxCode);
		 
	  }
	 
	//获得打印机的个数
	  function getPrinterCount() {
			LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
			return LODOP.GET_PRINTER_COUNT();
	  }
	//根据打印机序号获得打印机名称
	  function getPrinterName(iPrinterNO) {
			LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
			return LODOP.GET_PRINTER_NAME(iPrinterNO);
	  }
	  
	  
	  function printBarCode(printName, taskName) {
			LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
			LODOP.PRINT_INIT(taskName);
			LODOP.SET_PRINT_PAGESIZE(1, 600, 320, "");
			LODOP.ADD_PRINT_BARCODE(25, 10, 200, 45, "128B", taskName);
			LODOP.SET_PRINT_STYLE("FontName","SimHei");
		    LODOP.SET_PRINT_STYLE("FontSize",25);
			LODOP.ADD_PRINT_TEXT(70, 28, 200,100,taskName);
			if (LODOP.SET_PRINTER_INDEXA(printName)) {
				LODOP.PRINT();
			}
	  }
</script>
</head>

<body>
<section class="content">
 	<c:if test="${not empty message}">
		<div id="message" class="alert alert-success"><button data-dismiss="alert" class="close">×</button>${message}</div>
	</c:if>
	<div class="row">
		<div class="col-md-12">

			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">搜索栏</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
	<form class="form-search" id="queryForm"  >
	    <input id="_orderbystatus" name="_orderbystatus"  value="status" type="hidden"/>
		<div class="form-group row">
			<div class="col-sm-3">
			<div class="input-group col-sm-12">	
				<label class="input-group-text">仓库:</label>
				   <select  name="search_warehouseCode"  id="search_warehouseCode" value="${param._warehouseCode}"  class="form-control required" >
				     <option value=""></option> 
				     <c:forEach items="${warehouseList}" var="warehouse">
				       <option value="${warehouse.groupCode}" 
				       <c:if test="${param._warehouseCode eq warehouse.groupCode }">selected=selected</c:if>
				       >${warehouse.groupName}</option>
				     </c:forEach>
				</select>
			</div>
			</div>
		 	<div class="col-sm-3">
				<div class="input-group col-sm-12">
					<label  class="input-group-text" >LPNNO:</label>
					<input type="text" id="search_lpnNo" class="form-control" name="search_lpnNo" />
				</div>
		    </div>
		    <div class="col-sm-3">
			<div class="input-group col-sm-12">	
				<label class="input-group-text">类型：</label> 
				<select  name="search_type"  id="search_type"  class="form-control">
				    <option value="" ></option>
				    <option value="0">默认收货用</option>
				    <option value="1">托盘</option>
				</select>
			</div>
			</div>
			<div class="col-sm-3">
			<div class="input-group col-sm-12">	
				<label class="input-group-text">状态：</label> 
				<select  name="search_status"  id="search_status" value="${param._status}"  class="form-control">
				    <option value=""  ></option>
				    <option value="0" <c:if test="${status eq '0'}">selected=selected</c:if> >空闲</option>
				    <option value="1" <c:if test="${status eq '1'}">selected=selected</c:if> >使用中</option>
				</select>
			</div>
			</div>
			<div class="col-sm-3">
			<div class="input-group col-sm-12">	
			    <button type="button" class="btn btn-info" onclick="load()">搜索</button>
			    <a class="btn btn-info " href="${ctx}/v2_lpn/create">新增LPN</a>
			    <a href='#inputFile'  class='btn btn-primary' role='button' data-toggle='modal' >导入LPN</a>
			 </div>
			</div>
		    </div>
		  
	   </form>
	</div>
	</div>
	</div>
	</div>
	
	
	<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-list"></i>
					<h3 class="box-title">查询结果</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse" type="button">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">

	
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead><tr>
		    <th style="width: 60px;">序号</th>
		    <th style="width: 60px;">仓库</th>
		    <th style="width: 60px;">lpn</th>
		    <th style="width: 60px;">单号</th>
		    <th style="width: 60px;">类型</th>
		    <th style="width: 60px;">状态</th>
			<th style="width: 180px;">操作</th>
		</tr></thead>
		<tbody>
		</tbody>
	</table>
	</div>
	</div></div>
	</div>
	

     <!-- 打印条码窗体1 -->
	<div  class="modal  fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" id="selextPrinter" >
		 <div class="modal-dialog" style="width:1000">
		<div class="modal-content">
		 <div class="modal-header">
			  <h3 id="printerNumber">打印条码</h3>
		  </div>
			
		  <div class="modal-body" style="margin-left: 100px;">
			  <select id="printerBody" name="printerBody" style="width: 300px;"></select>
		  </div>
			
		  <div class="modal-footer">
		      <a role="button" id="printer" class="btn btn-primary" onclick="clickPrinter();"  data-dismiss="modal">开始打印</a>
			  <button class="btn btn-primary"  data-dismiss="modal" aria-hidden="true">取消</button>
		  </div>
		  </div></div>
	</div>
	<!-- 弹出窗体-导入LPN start  -->
	<div id="inputFile" class="modal fade">
		<div class="modal-dialog" style="width: 60%;">
			<div class="modal-content">
				<div class="modal-body">
					<div class="box box-solid box-primary">
			      		<div class="box-header"><span class="box-title">导入LPN</span></div>
						<div class="box-body">
							<form id="form1"  method="post" enctype="multipart/form-data">
								<table class="table table-striped table-bordered table-condensed">
									<tbody>
					
										<tr>
											<td>
												 <select  name="file_lpnType"  id="file_lpnType"   class="form-control required" >
												     <option value="0">默认收货用</option> 
												     <option value="1">托盘</option>
												</select>
											</td>
										</tr>
										<tr>
											<td>
												<input name="file" class="btn" type="file">
											</td>
										</tr>
										<tr>
											<td style="height: 50px; vertical-align: middle;">
												<input id="submit_btn" class="btn btn-primary" type="submit" value="提交" />
												<button type="reset" class="btn">
													重置
												</button>
											</td>
										</tr>
								  </tbody>
							   </table>
						   </form>
						</div>
					</div>
				</div>
				
			</div>	
		</div>
	</div>
	<!-- 弹出窗体-导入LPN end  -->
	<script type="text/javascript">
	$("#submit_btn").click(
			function() {
				 showBg();
				var file_lpnType = $("#file_lpnType").val();
				$("#form1").attr(
						"action",
						"${ctx}/v2_lpn/importExcel/" + file_lpnType);
			});

	action=""
	</script>
</section>	
</body>
</html>
